package com.hetao.xx.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.hetao.xx.Global;
import com.hetao.xx.R;
import com.hetao.xx.game.model.User;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class MineFragment extends Fragment {

    private View root;
    private Unbinder unbinder;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_name)
    TextView userName;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_hp)
    TextView userHp;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_mp)
    TextView userMp;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_attack)
    TextView userAttack;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_defence)
    TextView userDefence;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_speed)
    TextView userSpeed;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_xinfa)
    TextView userXinfa;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_wugong)
    TextView userWugong;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_qingong)
    TextView userQinggong;
    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.user_weapon)
    TextView userWeapon;


    public Handler mHandler = new Handler(Looper.getMainLooper()) {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    break;

            }
        }
    };

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (root == null) {
            root = inflater.inflate(R.layout.fragment_main_mine, container, false);
            unbinder = ButterKnife.bind(this, root);
        }

        return root;
    }

    public void refreshUserInfo() {
        User user = Global.getInstant().getUser();

        userName.setText(user.info.name);
        userHp.setText(String.valueOf(user.info.Hp));
        userMp.setText(String.valueOf(user.info.Mp));
        userAttack.setText(String.valueOf(user.info.attack));
        userDefence.setText(String.valueOf(user.info.defence));
        userSpeed.setText(String.valueOf(user.info.speed));


    }

    @Override
    public void onResume() {
        super.onResume();
        refreshUserInfo();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //进行判空，避免空指针
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
}
